#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int _maxR(TreeNode* root)
    {
        if (root == nullptr)
            return 0;
        int left = _maxR(root->left) + 1;
        int right = _maxR(root->right) + 1;
        return (left > right) ? left : right;
    }

    int maxDepth(TreeNode* root) {
        return _maxR(root);
    }
};

class Solution {
public:
    int _minR(TreeNode* root)
    {
        if (root == nullptr)
            return 0;
        int left = _minR(root->left);
        int right = _minR(root->right);
        if (root->right == nullptr && root->left != nullptr)
            return 1 + left;
        if (root->left == nullptr && root->right != nullptr)
            return 1 + right;
        int min = left > right ? right : left;
        return min + 1;
    }
    int minDepth(TreeNode* root) {
        return _minR(root);
    }
};

class Solution {
public:
    void _countR(TreeNode* root, int& count)
    {
        if (root == nullptr)
            return;
        count++;
        _countR(root->left, count);
        _countR(root->right, count);
    }
    int countNodes(TreeNode* root) {
        int count = 0;
        _countR(root, count);
        return count;
    }
};